package sctu.edu.java.year2016.team01.xuhanmei.day20160527.Printer1;

/**
 * Created by Administrator on 2016/5/27.
 */
public class PrintFactory {//用来容纳那部分经常重复的代码

    public static Printer getP(int flag) {//把flag传进来
        Printer p = null;
        if (flag == 1) {
            p = new HPPrinter();//向上转型
        } else if (flag == 2) {
            p = new Canonprinter();
        }
        else if(flag==3){
            p=new LGPrinter();
        }
        return p;//著名的工厂方法模式

    }
}
